package com.turing.usdtpay.mvp.activity;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.turing.usdtpay.R;
import com.turing.usdtpay.base.BaseActivity;
import com.turing.usdtpay.mvp.contract.InviteContract;
import com.turing.usdtpay.mvp.presenter.InvitePresent;
import com.turing.usdtpay.mvp.view.BaseTitleView;
import com.turing.usdtpay.utils.ToastUtils;

/**
 * @作者：JAY
 * @创建时间：2019/10/16 17:57
 * @描述：
 **/
public class InviteActivity extends Activity implements View.OnClickListener ,InviteContract.View {

    private BaseTitleView mTitle;
    private Button mCopy;
    private TextView mInvite;
    private InviteContract.Present mPresent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invite);
        initView();
        initTitle();
        setPresenter(new InvitePresent(this));
        initData();
    }

    private void initData() {
        mPresent.getInvite(this);
    }

    private void initTitle() {
        mTitle.setLeftShow(true);
        mTitle.setTitle("邀请好友");
        mTitle.setRightShow("我的团队",true);
        mTitle.setLeftButtonListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTitle.setRightButtonListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(InviteActivity.this,TeamActivity.class));
            }
        });
    }

    private void initView() {
        mTitle = (BaseTitleView) findViewById(R.id.title);
        mInvite = (TextView) findViewById(R.id.tv_invite);
        mCopy = (Button) findViewById(R.id.btn_copy);
        mCopy.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == mCopy.getId()){
            ClipboardManager mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData data = ClipData.newPlainText("bank",mInvite.getText().toString());
            mClipboard.setPrimaryClip(data);
            ToastUtils.showNormolToast(this,"复制成功");
        }
    }

    @Override
    public void getSuccess(String invite) {
        mInvite.setText(invite);
    }

    @Override
    public void onFail(String msg) {
        ToastUtils.showNormolToast(this,msg);
    }

    @Override
    public void setPresenter(InviteContract.Present presenter) {
        mPresent = presenter;
    }
}
